package com.zxc.csms.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.zxc.csms.common.TimeFormatType;

public class DateTool {

	/**
	 * 长整形时间转化成字符型的时间
	 * 
	 * @param format
	 * @param time
	 * @return
	 */
	public static String convertDateLongToDateString(TimeFormatType format, Long time) {
		if (null == time) {
			return "";
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format.getTimeFormatType());
		Timestamp now = new Timestamp(time);
		return sdf.format(now);
	}

	/**
	 * 字符型的时间转化成长整形的时间
	 * 
	 * @param format
	 * @param time
	 * @return
	 * @throws ParseException
	 */
	public static Long convertDateStringToDateLong(TimeFormatType format, String time)
			throws ParseException {
		if (null == time || "".equals(time.trim())) {
			return null;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format.getTimeFormatType());
		Date date = sdf.parse(time);
		return date.getTime();
	}

}
